<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Customer Wise Outstanding</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link href="globalCSS.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">


<style>
	.hidden 
	{
		display : none
	}
</style>
</head>
<body>

<form>
<h2 align="center"> Customer wise outstanding</h2>
<table border=2 align="center">
<tr>
		<td>Customer Code </td>
    	<td>Name of the Customer</td>
    	<td>Balance Outstanding </td>
    	</tr>

		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			 String inv="",dte="",nm="",cd="",cd1="",inn="";
			 double amt=0.0,in=0.0,adj=0.0,bal=0.0,bl=0.0;
			 
			 %>
			 
			 
			 <%
			try
			{
			   st=con.createStatement() ;
			   
			   rs=st.executeQuery("select date,svname,ccode,innum, sum(balance) from salesinvoiceoutstanding group by ccode");
	        	//rs=st.executeQuery("select date,");
	         while(rs.next()){ 
	        	 dte=rs.getString(1);
	 			nm=rs.getString(2);
	 			cd=rs.getString(3);
	 			
	 			inn=rs.getString(4);
	 			 in=rs.getDouble(5);
	 		
	         %>
	         <tr>
	         <td><%=cd%></td>
	         <td><a href="http://localhost:8081/BOA_Web/CustomerWiseServlet?custinv=<%=inn%>&custname=<%=nm%>&custcode=<%=cd%>&group=salesinvoice"><%=nm%></a></td>
	       
	         <td><%=in%></td>
	         </tr>

			   
					  <%}
			 rs=st.executeQuery("select date, ccode,innum,scname, sum(stota) from salesvoucher2 where ccode <> '"+cd+"' group by ccode");
			  while(rs.next())
			  { 
			String dt=rs.getString(1);
			 cd1=rs.getString(2);
			String inn1=rs.getString(3);
			String name=rs.getString(4);
			double tot=rs.getDouble(5);
			%>
			
			
			<tr>
	         <td><%=cd1%></td>
	         <td><a href="http://localhost:8081/BOA_Web/CustomerWiseServlet?custinv=<%=inn1%>&custname=<%=name%>&custcode=<%=cd1%>&group=sales"><%=name%></a></td>
	       
	         <td><%=tot%></td>
	         </tr>
			 
       		
  
	 		<%
	 		}
			}
					catch(Exception e){} %>
					
					
					

</table>
<script>
$('tr').each(function () {
	  a = $(this).children('td:eq(2)').text();
	  if (a == "0.0") {
	      $(this).addClass('hidden');
	  }
	})
</script>
</form>
<br>
<center><input type="button" value="Print this page" onClick="window.print()"></center>

<br><br>
<center><a href="HomePage.jsp">Back to Home Page</a></center>
</body>
</html>